/*
 * Created on May 3, 2004
 *
 * Vectrics Inc.  GNU Public License.
 */
package org.vectrics.recruiter.reporting;

import java.awt.Color;
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPCell;
import org.apache.log4j.Logger;
import org.vectrics.SystemException;
import org.vectrics.VectricsException;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.config.RecruitConfig;
import org.vectrics.recruiter.job.Job;
import org.vectrics.recruiter.job.JobSearchCriteria;
import org.vectrics.recruiter.job.JobProvider;
import org.vectrics.recruiter.job.JobStatusType;
import org.vectrics.struts.PhraseManager;
import org.vectrics.common.reporting.pdf.ReportUtil;
import org.vectrics.company.Company;
import org.vectrics.domain.Domain;
import org.vectrics.hibernate.ThreadProperties;

import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
import java.text.*;


/**
 * @author mmoore
 */
public abstract class VectricsPdfTable {
	private transient static Logger log = Logger.getLogger(VectricsPdfTable.class);
	private Domain domain = null;
	private Locale locale = null;
	private PdfPTable table = null;
	
	public VectricsPdfTable(Domain domain, Locale locale) {
		try {
			this.locale = locale;
			this.domain = domain;
		} catch (Exception ex) {
			throw new SystemException("Exception constructing pdf table", ex);
		}
	}
	
	public PdfPTable getTable() {
		return(this.table);
	}
	
	public void addCell(PdfPCell cell) {
		this.table.addCell(cell);
	}
	
	protected String getPhrase(String code) {
		String name = CoreServiceLocator.getPhraseProvider().getMessage(code, this.locale);
		return(name);
	}

	abstract protected int getColumnCount();
	abstract protected int getColumnWidth(int columnNumber);
	
	protected abstract void doFill(PdfPTable table);
	
	public void fill() {
		this.table = new PdfPTable(this.getColumnCount());
		int columnIndex = 0;
		int columnWidths[] = new int[this.getColumnCount()];
		for (columnIndex = 0; columnIndex < this.getColumnCount(); columnIndex++) {
			columnWidths[columnIndex] = this.getColumnWidth(columnIndex);
		}
		
		try {
			this.table.setWidths(columnWidths);
			this.table.setHorizontalAlignment(Element.ALIGN_LEFT);
			this.table.setWidthPercentage(100);
		} catch (Exception ex) {
			throw new SystemException("Exception setting table propertied", ex);
		}

		
		doFill(this.table);
	}
	
}
